Look at the following code:
int i
{
int j ;
{
int k ;
}
}
Is i
global or local?
Can I access i
from within the block where k
is declared?
What happens to the value of k
when the its block is exited?
If I declared a variable called i
in the same block where k
is declared, what happens?
Answers
-
i is global, as it is declared outside any block
-
Yes, because you can always access variables from the enclosing block
-
It is discarded
-
The compiler is quite happy, but if you refer to i in this block you will get hold of the contents in that block. You won't be able to refer to the global i at all